<?php
class Controller_Trajet extends Controller_Template{

	protected $categoriesModel;
	
	protected function __construct(){
		parent::__construct();
		$this->selfModel = new Model_Trajet();
		$this->categoriesModel = NULL;
	}

	public function index(){
		$title = "Liste des trajets";
		$this->categoriesModel = new Model_Category();
		$categories = $this->categoriesModel->getAll();
		
		foreach($categories as $i => $category){
			$categories[$i]['trajet'] = $this->selfModel->getByCategory(
			$category['id']);
		}
		
		header('Content-Type: text/html; charset=utf-8');
		require 'View/header.tpl';
		require 'View/book/index.tpl';
		require 'View/footer.tpl';
	}
	
	public function display($id){
		$trajet = $this->selfModel->getById($id);
		if(!$trajet){
			Controller_Error::documentNotFound();
		}
		else{
			$title = $trajet['title'];
			header('Content-Type: text/html; charset=utf-8');
			require 'View/header.tpl';
			require 'View/Trajet/display.tpl';
			require 'View/footer.tpl';
		}
	}
}

